var bg = chrome.extension.getBackgroundPage();

$(function(){
    function init() {
        $('#curPrice').text(bg.curPrice);
        $('#firstBuy').text(bg.firstBuy);
        $('#firstSell').text(bg.firstSell);
        $('#sellPrice').val(window.localStorage.expectedSellPrice);
        $('#coinName').val(window.localStorage.coinName);
        $('#buyPrice').val(window.localStorage.expectedBuyPrice);
        $('#boughtPrice').val(window.localStorage.buyPrice);
        $('#amount').val(window.localStorage.amount);
        $('#asset').text((bg.curPrice*window.localStorage.amount).toFixed(2));
        $('#working').prop("checked",window.localStorage.working);
    }

    init();
    //自动按钮
    $("#set").click(function(){
        window.localStorage.coinName = $('#coinName').val();
        window.localStorage.expectedSellPrice = $('#sellPrice').val();
        window.localStorage.expectedBuyPrice = $('#buyPrice').val();
        window.localStorage.buyPrice = $('#boughtPrice').val();
        window.localStorage.working = $('#working').prop("checked");
        window.localStorage.amount = $('#amount').val();
        bg.alert('设置成功！')
    });
});